package net.yxsoft.common;


import com.jfinal.kit.PropKit;
import net.yxsoft.constant.ConstantCacheInit;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class AppConfig {


    private static String redisHost= PropKit.get( ConstantCacheInit.CONFIG_REDIS_IP);


    private static String redisPort= PropKit.get(ConstantCacheInit.CONFIG_REDIS_PORT);


    private static String redisPwd= PropKit.get(ConstantCacheInit.CONFIG_REDIS_PASSWD);

    private static RedissonClient redisson = null;

    public static RedissonClient redissonClient(){
        Config config = new Config();
        //单机
        config.useSingleServer()
                .setPassword(redisPwd)
                .setTimeout(1000)
                .setRetryAttempts(3)
                .setRetryInterval(1000)
                .setPingConnectionInterval(1000) //**此项务必设置为redisson解决之前bug的timeout问题关键*****
                .setAddress("redis://"+redisHost+":"+redisPort);

        //集群
        //config.useClusterServers().setScanInterval(2000).addNodeAddress("redis://10.0.29.30:6379", "redis://10.0.29.95:6379");

        redisson = Redisson.create(config);
        return redisson;
    }

    public static RedissonClient getRedisson(){
        return redisson;
    }
}
